package com.guet.game.airplanes.dao;

import com.guet.game.utils.Audio;
import com.guet.game.weapon.Bullet;

import java.awt.*;
import java.awt.image.BufferedImage;
import java.awt.image.ImageObserver;

public abstract class FlyingObj {

    protected static final int LIFT = 0;
    protected static final int DEAD = 1;
    protected static final int REMOVE = 2;
    protected int state = 0;
    protected int width;
    protected int height;
    protected int x;
    protected int y;

    protected int index = 0;
    protected int boomIndex = 0;

    protected int currentHp;
    protected int maxHp;

    public FlyingObj(int width, int height) {
        this.width = width;
        this.height = height;
        x = (int) (Math.random() * (420 - 2 * this.width) + this.width);

        y = -height;

    }

    public FlyingObj(int width, int height, int x, int y) {
        this.width = width;
        this.height = height;
        this.x = x;
        this.y = y;

    }

    public Bullet[] shoot(){
        int xStep = this.width / 4;
        int yStep = 20;
        Bullet[] bullets = new Bullet[1];
        bullets[0] = new Bullet(this.x + 2 * xStep - 4, this.y - yStep, -4, Bullet.Type.line);
        return bullets;
    }

    public abstract BufferedImage getImage();

    public abstract void move();

    public void paintObj(Graphics g) {
        //System.out.println(this.getImage());
        g.drawImage(this.getImage(), this.x, this.y, null);
    }

    public boolean hit(FlyingObj obj) {
        return (obj.x + obj.width >= this.x &&
                obj.x <= this.x + this.width &&
                obj.y <= this.y + this.height &&
                obj.y + obj.height >= this.y);
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public boolean isLife() {
        return state == LIFT;
    }

    public boolean isDead() {
        return state == DEAD;
    }

    public boolean isRemove() {
        return state == REMOVE;
    }

    public int getWidth() {
        return width;
    }

    public int getHeight() {
        return height;
    }

    public void goDead() {
        state = DEAD;
    }

}
